package com.eedi.framework.event.dal.mapper;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.eedi.framework.common.event.annotations.event.EediEventPoint;
import com.eedi.framework.event.controller.vo.SysEventObsOrgResp;
import com.eedi.framework.event.convert.SysEventObsOrgConvert;
import com.eedi.framework.event.dal.dataobject.SysEventObsOrgDO;
import com.eedi.framework.mybatis.core.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface SysEventObsOrgMapper extends BaseMapperX<SysEventObsOrgDO> {


    default SysEventObsOrgResp getById(String id) {
        SysEventObsOrgDO sysEventObsOrgDO = selectById(id);
        return SysEventObsOrgConvert.INSTANCE.convert(sysEventObsOrgDO);
    }

    default List<SysEventObsOrgResp> getByPoint(EediEventPoint point) {
        if(ObjectUtil.isEmpty(point)){
            return List.of();
        }
        List<SysEventObsOrgDO> sysEventObsOrg = selectList(new LambdaQueryWrapper<SysEventObsOrgDO>()
                .eq(SysEventObsOrgDO::getSysEventType,point.getEventType())
                .eq(SysEventObsOrgDO::getSysEventPointCode,point.getCode()));
        return sysEventObsOrg.stream().map(SysEventObsOrgConvert.INSTANCE::convert).toList();
    }
}
